package cn.edu.sgu.www.mhxysy.enums;

import cn.edu.sgu.www.mhxysy.exception.GlobalException;
import cn.edu.sgu.www.mhxysy.restful.ResponseCode;

/**
 * 锁定状态枚举
 * @author 沐雨橙风ιε
 * @version 1.0
 */
public enum LockStatus {

    /**
     * 未锁定
     */
    UN_LOCK(0, "未锁定"),
    /**
     * 已锁定
     */
    LOCK(1, "已锁定");

    private final Integer value;
    private final String name;

    LockStatus(Integer value, String name) {
        this.value = value;
        this.name = name;
    }

    public Integer getValue() {
        return value;
    }

    public String getName() {
        return name;
    }

    /**
     * 判断是否为锁定状态
     * @param unlockState 解锁状态
     * @return 未解锁返回true，否则返回false
     */
    public static boolean isLocked(int unlockState) {
        if (LOCK.value != unlockState && UN_LOCK.value != unlockState) {
            throw new GlobalException(ResponseCode.BAD_REQUEST, "非法的状态值：" + unlockState);
        }

        return LOCK.value.equals(unlockState);
    }

}